<?php
// Copyright 2012 @Wondershare
// $Id: index.class.php 1 2012-11-9����9:16:46Z Administrator $

final class Route
{
	private $_controller = null;
	
	private $_method = null;

	public function __construct()
	{
		$this->_parseURI();
	}
	
	public function getController()
	{
		return $this->_controller;
	}
	
	public function getMethod()
	{
		return $this->_method;
	}
	
	/**
	 * url格式：/controller/action/other/.../?x=xxx&y=yyy....
	 */
	private function _parseURI()
	{
		$request_uri = $_SERVER['REQUEST_URI'];
		if(strpos($request_uri, '?') !== false)
			$request_uri = substr($request_uri, 0, strpos($request_uri, '?'));
		$request_uri = trim($request_uri, '/');
		$request_uri = explode('/', $request_uri);
		$count = count($request_uri);
		
		if($count == 0 || empty($request_uri[0]) ) 
		{
			$this->_default() ;
			return ;
		}
		switch ($count)
		{
			case 1:
				$this->_controller = $request_uri[0];
				$this->_method = 'index';
				break;
			case 2:
				$this->_controller = $request_uri[0];
				$this->_method = $request_uri[1];
				break;
			default : 	//TODO  在此进行扩展
				$this->_default() ;
				break ;
		}
		
	}
	
	/**
	 * 默认的controller和action
	 */
	private function _default()
	{
		$this->_controller = 'index';
		$this->_method = 'index';
	}
	
}